<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <base href="${APP_PATH}/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>考勤情况</title>
    <link rel="icon" href="public/favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <jsp:include page="/commons.jsp"></jsp:include>
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <jsp:include page="/menu.jsp"></jsp:include>

        <!--End 左侧导航-->

        <!--头部信息-->
        <jsp:include page="/head.jsp"></jsp:include>

        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">


                                <div class="col-lg-2">
                                    <input class="form-control" type="text" id="nameLike" name="nameLike"  value="" placeholder="输入查询学员姓名" />
                                </div>
                                <div class="toolbar-btn-action">
                                    <button class="btn btn-success m-r-5" id="search" type="button">查询</button>



                                </div>
                            </div>

                                <div class="card-body">

                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>学生编号</th>
                                                <th>学生姓名</th>
                                                <th>出勤/%</th>
                                                <th>迟到/%</th>
                                                <th>请假/%</th>
                                                <th>查看</th>
                                            </tr>
                                            </thead>
                                            <tbody id="dataList">
                                            <script id="dataTpl" type="text/javascript">
                                                {{each users user}}
                                                <tr>
                                                <td>{{$index+1}}</td>
                                                <td>{{user.sno}}</td>
                                                <td>{{user.uname}}</td>
                                                <td>
                                                {{if user.normal == 'NaN'}}     {{/if}}
                                                {{if user.normal != 'NaN'}} <span class="text-success" >{{user.normal}}</span>    {{/if}}
                                                </td>
                                                <td>
                                                {{if user.late == 'NaN'}}     {{/if}}
                                                    {{if user.late != 'NaN'}} <span class="text-danger" >{{user.late}}</span>    {{/if}}

                                                </td>
                                                <td>
                                                {{if user.vacate == 'NaN'}}     {{/if}}
                                                    {{if user.vacate != 'NaN'}}   <span class="text-purple" >{{user.vacate}}</span>  {{/if}}

                                                </td>
                                                        <td>
                                                        <button class="detailBtn btn btn-success" snumber="{{user.sno}}" sname="{{user.uname}}" normal="{{user.normal}}" late="{{user.late}}" vacate = "{{user.vacate}}" va data-toggle="modal" data-target="#pieModal" >查看饼图</button>
                                                    </td>
                                                </tr>
                                                {{/each}}
                                            </script>
                                            </tbody>
                                        </table>
                                    </div>

                                    <ul class="pagination" id="pageList">



                                    </ul>

                                </div>
                        </div>

                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<button ></button>
<!-- Start 考勤情况模态框 -->
<div class="modal fade bs-example-modal-lg in" id="pieModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" align="center">
            <input type="hidden" id="pageNum" />
            <div class="modal-header">

                <button type="button" id="XBtn" class="close" data-dismiss="modal" aria-label="Close" ><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>

            <div class="modal-body " align="center" id="body">




            </div>
            <div class="modal-footer">
                <button type="button" id="closeBtn" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!-- End 请假审批模态框 -->



<!--日期选择插件-->
<script src="public/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="public/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<!-- 图 -->
<script type="text/javascript" src="public/js/Chart.js"></script>
<script type="text/javascript">



    $(function(){
        $('.search-bar .dropdown-menu a').click(function() {
            var field = $(this).data('field') || '';
            $('#search-field').val(field);
            $('#search-btn').html($(this).text() + ' <span class="caret"></span>');
        });
        <!-- start detailBtn 点击显示饼图模态框 -->
        var normal = 0;
        var late = 0;
        var vacate = 0;
        var snumber = "";
        var sname = "";
            $(document).on("click",".detailBtn",function () {
                //每次点击重新添加；画布，即可避免产生每点击一次显示文本变小
                var bodyHtml = ' <canvas id="chart-doughnut" width="400" height="400"></canvas>';
                $("#body").html(bodyHtml);
                var myChart = null;
                snumber = $(this).attr("snumber");
                sname = $(this).attr("sname");
                $("#myModalLabel").text("学号："+snumber+"，姓名："+sname+"的考勤情况(%)");

                normal = $(this).attr("normal");
                late = $(this).attr("late");
                vacate = $(this).attr("vacate");

                myChart =  new Chart($("#chart-doughnut"), {
                    type: 'doughnut',
                    data: {
                        labels: ["迟到", "正常", "请假"],
                        datasets: [{
                            data: [late, normal, vacate],
                            backgroundColor: ['rgba(255,99,132,1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)']
                        }]
                    },
                    options: {
                        responsive: false,
                        animateRotate : true
                    }
                });//new chart
            });
        <!-- end detailBtn 点击显示饼图模态框 -->



        //多条件分页查询
        var examplesMap ="";
        $("#search").click(function () {

            var nameLike = $("#nameLike").val();

            examplesMap = {"nameLike":nameLike};

            examplesMap = JSON.stringify(examplesMap);
            goPage("1",examplesMap);
        });//多条件分页查询

        //点击page跳转页面
        $(document).on("click",".page" , function (event) {
            let page = $(this).attr("data-page");
            goPage(page,examplesMap);
        })//点击page跳转页面

        //进入页面展示学员考勤表
        layer.msg("加载中", {time:200, icon:16, shift:5}, function(){
            goPage("1","");
        });//layer


    });//入口






    function goPage(pageNum,examplesMap){
        $.ajax({
            url:"attendance/listStudentInfo",
            data:{"uid":"${loginUser.uid}","pageNum":pageNum,"examplesMap":examplesMap},
            dataType:"json",
            type:"post",
            success:function (result) {
                if(result.result){
                    $("#pageNum").val(result.pageInfo.pageNum);
                    //展示考勤信息列表
                    let dataHtml = template("dataTpl", {
                        users : result.userList
                    });
                    $("#dataList").html(dataHtml);


                    //对pageInfo判空，若为null直接退出
                    if(result.pageInfo == null){
                        layer.msg("无数据", {time:1000, icon:5, shift:6}, function () {});
                        return;
                    }


                    //start - 生成页码
                    $("#pageList").empty();
                    var pageListHtml = "共有数据"+(result.pageInfo.total)+"条，当前页为第"+result.pageInfo.pageNum+"页，展示数据"+result.pageInfo.size+"条";
                    if(result.pageInfo.pageNum == 1){
                        pageListHtml += "<li class='disabled'><span><a class='page'>«</a></span></li>";
                    }else{
                        pageListHtml += "<li class=''><span><a class='page' href='javascript:void(0)' data-page="+result.pageInfo.prePage+">«</a></span></li>";
                    }
                    for (var i = 1 ; i <= result.pageInfo.pages ; i++){
                        var aObj2 = "";
                        if(result.pageInfo.pageNum == i){
                            aObj2 = "<li class='active' ><a class='page' href= 'javascript:void(0)' data-page="+i+">"+i+"</a></li>";
                        }else{
                            aObj2 = "<li ><a class='page' href= 'javascript:void(0)' data-page="+i+">"+i+"</a></li>";
                        }
                        pageListHtml += aObj2;
                    }
                    if(result.pageInfo.pageNum == result.pageInfo.pages){
                        pageListHtml += "<li class='disabled'><span><a class='page' >»</a></span></li>";
                    }else{
                        pageListHtml += "<li class=''><span><a class='page' href='javascript:void(0)' data-page="+result.pageInfo.nextPage+">»</a></span></li>";
                    }
                    $("#pageList").html(pageListHtml);
                    //end - 生成页码
                }
            }//success
        });//ajax
    }//gopage
</script>
</body>
</html>
